#include <stdio.h>
#define MAX_SIZE 20000

int main() {
    int queue[MAX_SIZE];
    int front = 0,rear = 0;
    int n,op;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &op);
        if (op == 1) {
            int value;
            scanf("%d", &value);
            queue[rear++] = value;
        }else {
            if (front < rear) {
                printf("%d\n", queue[front++]);
            }else {
                printf("invalid\n");
            }
        }
    }
}